from selenium.webdriver.support.select import Select
from selenium.webdriver.support.wait import WebDriverWait


# 1.列出selenium常用的元素定位方式.
# id,name,class_name,link_text,css_seleector,xpath,partial_link_text

#
# 2.写出xpath属性和文本精准 & 模糊匹配语法, / 和 // 的区别. / a和 // * 代表什么.
# //tag[@属性名=属性值]  //tag[text()='文本值']
#/:绝对路径   //:相对路径
#//*:从html开始查找所有的标签元素    /a:查找所有的a标签元素
# 3.写出css_selector属性精准 & 模糊匹配语法.
#[属性名=属性值]    [属性名 *=属性值]:包含属性值 [属性名 ^=属性值]:以属性值开头  [属性名  $=属性值]:以属性值结尾
# 4.通过javascript结合selenium定位hao123链接, 移除target属性的脚本.
# js="document.getElementById('s-top-left').children[1].removeAttribute('target')"
# # driver.execute_script(js)
# element=driver.find_element_by_link_text('hao123')
# js="arguments[0].removeAttribute('target')"
# driver.execute_script(js,element)

# 5.写出打开浏览器进行窗口最大化, 隐式等待, 访问百度URL, 退出浏览器操作的脚本.
from  selenium import webdriver
driver=webdriver.Chrome()
driver.maximize_window()
driver.implicitly_wait(10)
driver.get('https://www.baidu.com/')
driver.quit()

# 6.写出三种切换的脚步.(window, frame, alert)
# handles=driver.window_handles
# driver.switch_to.window(handles[-1]) #默认为最后一个页面
#
# frame=driver.find_element_by_id('')
# driver.switch_to.frame(frame)#切入
# driver.switch_to.default_content()  #切出
#
# alter=driver.switch_to.alert
# alter.accept()  #确定
# alter.dismiss()  #取消
# alter.send_keys()  #输入框中输入信息

# 7.写出三种等待方式及它们的特点.
#sleep()  强制等待    implicitly_wait()  隐式等待 针对的是整个系统的页面  WebDriverWait显示等待，针对于页面中的元素
# 8.写出下拉框选项操作的脚本.
# sele=driver.find_element_by_id('')
# select=Select(sele)
# select.select_by_index(index) #下标
# select.select_by_value('') #value值
# select.select_by_visible_text('') #可见的文本内容
# 9.使用unittest对登录模块进行测试用例类的设计;
# 要求测试用例不少于6条
# 注: 登录模块页面有用户名 / 密码输入框, 登录按钮;
# 用户名和密码输入框的规则为
# 6 - 18位中英文数字
# 用户名: < input
# id = "username" >
# 密码: < input
# id = "password" >
# 登录按钮: < input >
# import unittest
# class TextLogin(unittest.TestCase):
#     @classmethod
#     def setUpClass(cls) -> None:
#         cls.driver = webdriver.Chrome()
#         cls.driver.maximize_window()
#         cls.driver.implicitly_wait(10)
#         cls.driver.get('URL')
#     def setUp(self) -> None:
#         pass
#     @classmethod
#     def tearDownClass(cls) -> None:
#         cls.driver.quit()
#     def tearDown(self) -> None:
#         self.driver.refresh()
#     def text_login_tc001(self):
#         self.driver.find_element_by_id('username').send_keys('zx123')
#         self.driver.find_element_by_id('password').send_keys('zas12')
#         self.driver.find_element_by_id('input').click()
#     def text_login_tc002(self):
#         self.driver.find_element_by_id('username').send_keys('zx123f')
#         self.driver.find_element_by_id('password').send_keys('zx123')
#         self.driver.find_element_by_id('input').click()
#     def text_login_tc003(self):
#         self.driver.find_element_by_id('username').send_keys('asdfg12345648aswqe')
#         self.driver.find_element_by_id('password').send_keys('zx123')
#         self.driver.find_element_by_id('input').click()
#     def text_login_tc004(self):
#         self.driver.find_element_by_id('username').send_keys('asdfg12345648aswqe4')
#         self.driver.find_element_by_id('password').send_keys('zx123')
#         self.driver.find_element_by_id('input').click()
#     def text_login_tc005(self):
#         self.driver.find_element_by_id('username').send_keys('asdfg12345648aswqe4')
#         self.driver.find_element_by_id('password').send_keys('zx1236')
#         self.driver.find_element_by_id('input').click()
#     def text_login_tc006(self):
#         self.driver.find_element_by_id('username').send_keys('asdfg12345648aswqe')
#         self.driver.find_element_by_id('password').send_keys('zx1234')
#         self.driver.find_element_by_id('input').click()
#
# if __name__ == '__main__':
#     unittest.main()

# 10.使用unittest收集TestLogin测试类中的测试用例, 运行并产生自动化测试报告文件test_report.html
import unittest
suite=unittest.TestSuite()
loader=unittest.TestLoader()
suite.addTests(loader.loadTestsFromTestCase(TextLogin))
from BeautifulReport import BeautifulReport
bf=BeautifulReport(suite)
bf.report('测试报告','./test_repoort.html')








